package com.dysf.proxy.dynamic;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @Description
 * @Author dysfzl
 * @Date 2022-01-08 11:53
 * @Copyright xx科技有限公司 Copyright (c)
 * @Version 1.0
 */
public class MyProxyJDK implements InvocationHandler {

    // 被代理的对象
    Object target;

    public MyProxyJDK(Object target) {
        this.target=target;
    }

    // 代理类的执行方法
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

        Object result=null;
        try {
            System.out.println("JDK动态代理--增强前");
            result = method.invoke(target, args);
            System.out.println("JDK动态代理--增强后");
        }catch (Exception ex){
            System.out.println("JDK动态代理--异常处理");
        }finally {
            System.out.println("JDK动态代理--方法结束");
        }

        return result;
    }
}
